const fs = require("fs")
const { promisify } = require('util')//express 自带的异步
const readFile = promisify(fs.readFile)//读文件
const writeFile =promisify(fs.writeFile)//写文件
const path = require('path')
const dbPath=path.join(__dirname,'./user.json')

exports.getUser =async () => {
    const data = await readFile(dbPath, 'utf8')
    return JSON.parse(data)
}

exports.saveUser = async (db) => {
    const data = JSON.stringify(db,null,' ')//第三个参数解决格式化问题
    await writeFile(dbPath,data)
}